package run.siyuan.manag.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import run.siyuan.manag.util.SecurityUtil;

import java.util.Date;

/**
 * @program: education-platform
 * @description: 创建时间、修改时间自动填充
 * @author: SY
 * @create: 2020-12-24 13:39
 **/
@Component
@Slf4j
public class CommonMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        // 用户名
        String username = SecurityUtil.getUsername();
        log.info("username:{}",username);
        this.setFieldValByName("createTime", new Date(), metaObject);
        this.setFieldValByName("createBy", username, metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        // 用户名
        String username = SecurityUtil.getUsername();
        log.info("username:{}",username);
        this.setFieldValByName("lastUpdateTime", new Date(), metaObject);
        this.setFieldValByName("lastUpdateBy",username,metaObject);
    }



}